package com.lksy.web.dao.system;

import java.sql.SQLException;
import java.util.List;
import java.util.Map;

import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanHandler;
import org.apache.commons.dbutils.handlers.MapListHandler;

import com.lksy.core.config.BaseDao;
import com.lksy.web.model.Admin;

public class AdminDao extends BaseDao {

	private static AdminDao adminDao = new AdminDao();
	
	public static AdminDao getInstance() {
		return adminDao;
	}
	
	public boolean login(String username,String userpassword) throws SQLException {
		QueryRunner runner = new QueryRunner(dataSource);
		Admin admin = runner.query("select * from t_manager where username=? and password=?", new BeanHandler<>(Admin.class) , new Object[]{username,userpassword});
		if(admin != null) {
			return true;
		} 
		return false;
	}
	
	public List<Map<String,Object>> loadAllSysLog() throws SQLException {
		QueryRunner runner = new QueryRunner(dataSource);
		return runner.query("select * from method_log", new MapListHandler());
	}
}
